package com.thales.sentinel;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import com.thales.sentinel.service.LicenseValidationService;
import com.thales.sentinel.model.LicenseException;

/**
 * Sentinel LDK Licensing Spring Boot Application
 * Spring Boot 主应用类
 * 启动时会自动验证许可证的有效性和过期时间
 */
@SpringBootApplication
public class LdkLicensingApplication {

    public static void main(String[] args) {
        try {
            System.out.println("正在启动 Sentinel LDK Licensing 应用...");
            System.out.println("正在验证许可证...");
            
            ConfigurableApplicationContext context = SpringApplication.run(LdkLicensingApplication.class, args);
            
            // 应用启动成功后的信息
            System.out.println("=".repeat(60));
            System.out.println("Sentinel LDK Licensing 应用启动成功!");
            System.out.println("API 接口:");
            System.out.println("  - 许可证验证: GET /api/license/validate");
            System.out.println("  - 许可证信息: GET /api/license/info");
            System.out.println("  - 创建用户: POST /api/license/users");
            System.out.println("  - 用户列表: GET /api/license/users");
            System.out.println("  - 健康检查: GET /api/license/health");
            System.out.println("=".repeat(60));
            
        } catch (Exception e) {
            System.err.println("应用启动失败: " + e.getMessage());
            if (e.getCause() instanceof LicenseException) {
                LicenseException licenseException = (LicenseException) e.getCause();
                System.err.println("许可证错误类型: " + licenseException.getErrorType());
                System.err.println("错误详情: " + licenseException.getMessage());
            }
            System.err.println("请检查许可证配置和加密狗连接状态");
            System.exit(1);
        }
    }
}